package com.itheima.mail.listener;

import com.alibaba.fastjson.JSON;
import com.itheima.utils.MailUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.util.Map;

//接收到发送邮件的消息之后的处理器
public class MailListener implements MessageListener {


    public void onMessage(Message message) {
        byte[] body = message.getBody();
        Map<String, String> map = JSON.parseObject(body, Map.class);// 将接收到的消息转换成map

        String to = map.get("to");
        String title = map.get("title");
        String content = map.get("content");

        System.out.println("接收到发送邮件的任务了, 收件人是" + to);
        MailUtil.sendMail(to, title, content);
        System.out.println("邮件发送完毕.......");
    }
    public void sms(Message message) {
        byte[] body = message.getBody();
        Map<String, String> map = JSON.parseObject(body, Map.class);// 将接收到的消息转换成map

        String to = map.get("to");
        String title = map.get("title");
        String content = map.get("content");

        System.out.println("接收到发送邮件的任务了, 收件人是" + to);
        MailUtil.sendMail(to, title, content);
        System.out.println("邮件发送完毕.......");
    }





}
